?><?
class cls_control_css extends cls_control{
	var $action	= "css";
	var $fname	= "grape_styles.css";

	function check_access(){return true;}

	function as_page(){
		// init
		$css="";
		$new_change_hash=0;
		header("Content-Type: text/css;");
		//
		$change_hash=$this->getSet("package_styles_hash");
		$predefined=array("grape/scripts/grape.css",);

		$registered=array_merge($predefined,$GLOBALS["package_styles"]);
		foreach($registered as $style){$new_change_hash+=filemtime($style);}
		
		$this->setSet("package_styles_hash",$new_change_hash);
		$change_hash=$new_change_hash;

		/// package and predefined styles
		foreach($registered as $style){
			$css.="\n/*compilled {$style}*/\n";
			$css.=file_get_contents($style);
			$css.="\n/*compilled {$style}*/\n";
		}
		
		/// user defined styles
		foreach(cls_style::get() as $style){
			$css.=$style->content;
		}
		file_put_contents($this->fname,$css);
		jr("ok");
	}
	
	function as_link(){
		?><!-- compilled styles --><?
		?><link href="<?=get_host()."/".$this->fname?>?<?=filemtime($this->fname)?>" rel="stylesheet" type="text/css" /><?
		?><!-- --><?
	}
}

